<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Introspecting static member function template</title>
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Chapter 1. The Type Traits Introspection Library">
<link rel="up" href="../index.html" title="Chapter 1. The Type Traits Introspection Library">
<link rel="prev" href="tti_detail_has_static_member_function.html" title="Introspecting static member function">
<link rel="next" href="tti_detail_has_data.html" title="Introspecting data">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
<td align="center"><a href="../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="tti_detail_has_static_member_function.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="tti_detail_has_data.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="the_type_traits_introspection_library.tti_detail_has_static_member_function_template"></a><a class="link" href="tti_detail_has_static_member_function_template.html" title="Introspecting static member function template">Introspecting
    static member function template</a>
</h2></div></div></div>
<p>
      We can introspect a static member function template of a user-defined type
      using the TTI functionality we shall now explain.
    </p>
<p>
      A static member function template is a function template that is a static memmber
      of a user-defined type. An example of a static member function template would
      be:
    </p>
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">AnotherType</span>
  <span class="special">{</span>
  <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">X</span><span class="special">,</span><span class="keyword">int</span> <span class="identifier">Y</span><span class="special">&gt;</span> <span class="keyword">static</span> <span class="keyword">int</span> <span class="identifier">AStaticFuncTemplate</span><span class="special">(</span><span class="identifier">X</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">{</span> <span class="special">...</span><span class="identifier">some</span> <span class="identifier">code</span> <span class="keyword">using</span> <span class="identifier">x</span><span class="special">;</span> <span class="keyword">return</span> <span class="identifier">Y</span><span class="special">;</span> <span class="special">}</span>
  <span class="special">};</span>
</pre>
<p>
      In order to introspect the function template we use some theoretical valid
      instantiation of the static member function template <code class="computeroutput"><span class="identifier">AStaticFuncTemplate</span></code>.
      An instantiation of a function template was previously explained in the topic
      <a class="link" href="tti_function_templates.html#sectti_function_templates">"Introspecting function templates
      technique"</a>.
    </p>
<p>
      For the purposes of illustration the instantiation we will use is:
    </p>
<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">AStaticFuncTemplate</span><span class="special">&lt;</span><span class="keyword">char</span><span class="special">,</span><span class="number">483</span><span class="special">&gt;(</span><span class="keyword">char</span><span class="special">)</span>
</pre>
<p>
      What we have now which the TTI will need in order to introspect the static
      member function template <code class="computeroutput"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">X</span><span class="special">,</span><span class="keyword">int</span> <span class="identifier">Y</span><span class="special">&gt;</span> <span class="keyword">static</span> <span class="keyword">int</span> <span class="identifier">AStaticFuncTemplate</span><span class="special">(</span><span class="identifier">X</span><span class="special">)</span></code>
      within the <code class="computeroutput"><span class="identifier">AnotherType</span></code> struct
      is:
    </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
          The name of <code class="computeroutput"><span class="identifier">AStaticFuncTemplate</span></code>
        </li>
<li class="listitem">
          The template parameters of <code class="computeroutput"><span class="keyword">char</span><span class="special">,</span><span class="number">483</span></code>
        </li>
<li class="listitem">
          The enclosing type of <code class="computeroutput"><span class="identifier">AnotherType</span></code>
        </li>
<li class="listitem">
          The return type of <code class="computeroutput"><span class="keyword">int</span></code>
        </li>
<li class="listitem">
          The function parameters of <code class="computeroutput"><span class="keyword">char</span></code>
        </li>
</ul></div>
<h4>
<a name="the_type_traits_introspection_library.tti_detail_has_static_member_function_template.h0"></a>
      <span class="phrase"><a name="the_type_traits_introspection_library.tti_detail_has_static_member_function_template.generating_the_metafunction"></a></span><a class="link" href="tti_detail_has_static_member_function_template.html#the_type_traits_introspection_library.tti_detail_has_static_member_function_template.generating_the_metafunction">Generating
      the metafunction</a>
    </h4>
<p>
      As with all TTI functionality for introspecting entities within a user-defined
      type introspecting a static member function template is a two step process.
      The first process is using a macro to generate a metafunction. The macro for
      static member function templates is <code class="computeroutput"><a class="link" href="../BOOST_TT_idm45828887612288.html" title="Macro BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION_TEMPLATE">BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION_TEMPLATE</a></code>.
      This macro takes the name of the member function template and the instantiated
      template parameters, the first two items in our list above:
    </p>
<pre class="programlisting"><span class="identifier">BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION_TEMPLATE</span><span class="special">(</span><span class="identifier">AStaticFuncTemplate</span><span class="special">,</span><span class="keyword">char</span><span class="special">,</span><span class="number">483</span><span class="special">)</span>
</pre>
<p>
      An alternative form for compilers which do not support variadic macros, and
      which will also work with compilers which do support variadic macros, is to
      specify the template parameters of the instantiation as a single macro argument
      using a Boost PP array:
    </p>
<pre class="programlisting"><span class="identifier">BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION_TEMPLATE</span><span class="special">(</span><span class="identifier">AStaticFuncTemplate</span><span class="special">,(</span><span class="number">2</span><span class="special">,(</span><span class="keyword">char</span><span class="special">,</span><span class="number">483</span><span class="special">)))</span>
</pre>
<p>
      The macro generates a metafunction based on the pattern of "has_static_member_function_template_'name_of_inner_static_member_function_template'",
      which in our example case would be <code class="computeroutput"><span class="identifier">has_static_member_function_template_AStaticFuncTemplate</span></code>.
    </p>
<h4>
<a name="the_type_traits_introspection_library.tti_detail_has_static_member_function_template.h1"></a>
      <span class="phrase"><a name="the_type_traits_introspection_library.tti_detail_has_static_member_function_template.invoking_the_metafunction"></a></span><a class="link" href="tti_detail_has_static_member_function_template.html#the_type_traits_introspection_library.tti_detail_has_static_member_function_template.invoking_the_metafunction">Invoking
      the metafunction</a>
    </h4>
<p>
      To use this macro to test whether our static member function template exists
      the metafunction the macro creates is invoked with the enclosing type, the
      instantiated return type, and the instantiated function parameters, with the
      resulting <code class="computeroutput"><span class="identifier">value</span></code> being a compile
      time boolean constant which is <code class="computeroutput"><span class="keyword">true</span></code>
      if the static member function template exists, or <code class="computeroutput"><span class="keyword">false</span></code>
      otherwise. There are two ways to do this. We can either use each of our needed
      types as separate parameters, with the instantiated function parameters being
      enclosed in an MPL forward sequence, or we can compose our needed type in the
      form of an enclosing type and a function type. In the first case we would have:
    </p>
<pre class="programlisting"><span class="identifier">has_static_member_function_template_AStaticFuncTemplate</span><span class="special">&lt;</span><span class="identifier">AnotherType</span><span class="special">,</span><span class="keyword">int</span><span class="special">,</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">char</span><span class="special">&gt;</span> <span class="special">&gt;::</span><span class="identifier">value</span>
</pre>
<p>
      and in the second case we would have:
    </p>
<pre class="programlisting"><span class="identifier">has_static_member_function_template_AStaticFuncTemplate</span><span class="special">&lt;</span><span class="identifier">AnotherType</span><span class="special">,</span><span class="keyword">int</span> <span class="special">(</span><span class="keyword">char</span><span class="special">)</span> <span class="special">&gt;::</span><span class="identifier">value</span>
</pre>
<p>
      Both invocations are equivalent in functionality.
    </p>
<h4>
<a name="the_type_traits_introspection_library.tti_detail_has_static_member_function_template.h2"></a>
      <span class="phrase"><a name="the_type_traits_introspection_library.tti_detail_has_static_member_function_template.other_considerations"></a></span><a class="link" href="tti_detail_has_static_member_function_template.html#the_type_traits_introspection_library.tti_detail_has_static_member_function_template.other_considerations">Other
      considerations</a>
    </h4>
<p>
      The macro for generating the metafunction for introspecting member function
      templates also has, like other macros in the TTI library, a complex macro form
      where the end-user can directly specify the name of the metafunction to be
      generated. The corresponding macro is BOOST_TTI_TRAIT_HAS_STATIC_MEMBER_FUNCTION_TEMPLATE,
      where the first parameter is the name of the metafunction to be generated,
      the second parameter is the static member function template name, and the remaining
      parameters are the instantiated template parameters. For our example we could
      have
    </p>
<pre class="programlisting"><span class="identifier">BOOST_TTI_TRAIT_HAS_STATIC_MEMBER_FUNCTION_TEMPLATE</span><span class="special">(</span><span class="identifier">AMetafunctionName</span><span class="special">,</span><span class="identifier">AStaticFuncTemplate</span><span class="special">,</span><span class="keyword">char</span><span class="special">,</span><span class="number">483</span><span class="special">)</span>
</pre>
<p>
      or for the non-variadic macro form
    </p>
<pre class="programlisting"><span class="identifier">BOOST_TTI_TRAIT_HAS_STATIC_MEMBER_FUNCTION_TEMPLATE</span><span class="special">(</span><span class="identifier">AMetafunctionName</span><span class="special">,</span><span class="identifier">AStaticFuncTemplate</span><span class="special">,(</span><span class="number">2</span><span class="special">,(</span><span class="keyword">char</span><span class="special">,</span><span class="number">483</span><span class="special">)))</span>
</pre>
<p>
      which generates a metafunction whose name would be <code class="computeroutput"><span class="identifier">AMetafunctionName</span></code>.
    </p>
<p>
      In all other respects the resulting metafunction generated works exactly the
      same as when using the simpler macro form previously illustrated.
    </p>
<p>
      If you do use the simple macro form, which generates the metafunction name
      from the name of the function template you are introspecting, you can use a
      corresponding macro, taking the name of the static member function template
      as a single parameter, to create the appropriate metafunction name if you do
      not want to remember the pattern for generating the metafunction name. This
      macro name is <code class="computeroutput"><span class="identifier">BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION_TEMPLATE_GEN</span></code>
      as in
    </p>
<pre class="programlisting"><span class="identifier">BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION_TEMPLATE_GEN</span><span class="special">(</span><span class="identifier">AStaticFuncTemplate</span><span class="special">)</span>
</pre>
<p>
      which would generate the name <code class="computeroutput"><span class="identifier">has_static_member_function_template_AStaticFuncTemplate</span></code>.
    </p>
<p>
      When invoking the appropriate metafunction using the long form of an enclosing
      type, instantiated return type, and instantiated function parameters, a fourth
      template argument may optionally be given which holds a Boost FunctionTypes
      tag type. This optional template argument is of much less use for static member
      function templates than for non-static member function templates since static
      member function templates, like static member functions, can not have cv-qualifications.
      which a number of Boost FunctionTypes tags provide. Nonetheless this optional
      Boost FunctionTypes tag is available for end-user use and may come in handy
      in certain rare cases, as when some calling convention qualification for the
      static member function template needs to be specified.
    </p>
<p>
      When invoking the metafunction using the shorter form of an enclosing type
      and a function type any possibly needed qualification can be added to the end
      of the function type.
    </p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2011-2013 Tropic Software
      East Inc<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="tti_detail_has_static_member_function.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="tti_detail_has_data.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
